# 彻底移除所有Java文件的BOM字符

$javaFiles = Get-ChildItem -Path "src\main\java" -Filter "*.java" -Recurse
$count = 0
$bomCount = 0

foreach ($file in $javaFiles) {
    try {
        $bytes = [System.IO.File]::ReadAllBytes($file.FullName)
        
        # 检查是否有BOM字符 (EF BB BF)
        if ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) {
            Write-Host "Removing BOM from: $($file.Name)"
            
            # 移除前3个字节（BOM）
            $newBytes = $bytes[3..($bytes.Length-1)]
            [System.IO.File]::WriteAllBytes($file.FullName, $newBytes)
            $bomCount++
        }
        
        $count++
        if ($count % 20 -eq 0) {
            Write-Host "Processed $count files..."
        }
    }
    catch {
        Write-Host "Error processing file: $($file.Name) - $($_.Exception.Message)"
    }
}

Write-Host "Processed $count files total. Removed BOM from $bomCount files."